using System.Collections;
using UnityEngine;

public class EOTD_CastleFloor_LockedDoor : MonoBehaviour
{
	[SerializeField]
	private string LancerSpokenPlayerPref = "EOTD_HasMetLancer";

	[SerializeField]
	private INT_Chat DoorChat;

	[SerializeField]
	private CHATBOXTEXT Door_PreventLeave;

	[SerializeField]
	private CHATBOXTEXT Door_AllowChoice;

	[SerializeField]
	private CHATBOXTEXT DoorCutscene_RalseiBegin;

	[SerializeField]
	private CHATBOXTEXT DoorCutscene_RalseiFinale;

	[Header("Cutscene")]
	[SerializeField]
	private int CutsceneIndex;

	[SerializeField]
	private Susie_Follower Susie;

	[SerializeField]
	private Susie_Follower Ralsei;

	[SerializeField]
	private CameraManager Camera;

	[SerializeField]
	private Vector3 KrisTargetPos;

	[SerializeField]
	private Vector3 SusieTargetPos;

	[SerializeField]
	private Vector3 RalseiTargetPos;

	[SerializeField]
	private SpriteRenderer backgroundRenderer;

	[SerializeField]
	private Sprite backgroundDoorOpenSprite;

	[SerializeField]
	private GameObject backgroundDoorGlow;

	[SerializeField]
	private AudioSource CutsceneSource;

	[SerializeField]
	private AudioClip DoorOpenSound;

	[SerializeField]
	private TRIG_LEVELTRANSITION LevelTransition;

	private void Start()
	{
		if (PlayerPrefs.GetInt(LancerSpokenPlayerPref, 0) == 0)
		{
			DoorChat.Text = Door_PreventLeave;
		}
		else
		{
			DoorChat.Text = Door_AllowChoice;
		}
		Susie = PartyMemberSystem.Instance.HasMemberInParty(PartyMemberSystem.Instance.Default_SusieDarkworld).PartyMemberFollowSettings;
		Ralsei = PartyMemberSystem.Instance.HasMemberInParty(PartyMemberSystem.Instance.Default_Ralsei).PartyMemberFollowSettings;
	}

	private void Update()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if (CutsceneIndex != 0)
		{
			CutsceneUpdate();
			PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Cutscene;
			PlayerManager.Instance._PMove.RotatePlayerAnim(Vector2.up);
			DarkworldMenu.Instance.CanOpenMenu = false;
			Camera.FollowPlayerX = false;
			Camera.FollowPlayerY = false;
		}
	}

	public void BeginEndCutscene()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		CutsceneIndex = 1;
		MusicManager.StopSong(Fade: true, 1f);
		Ralsei.FollowingEnabled = false;
		Ralsei.RotateSusieToDirection(Vector2.down);
		Susie.FollowingEnabled = false;
		Susie.RotateSusieToDirection(Vector2.up);
		PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Cutscene;
		DarkworldMenu.Instance.CanOpenMenu = false;
		PlayerManager.Instance._PMove.RotatePlayerAnim(Vector2.up);
		ChatboxManager.Instance.EndText();
	}

	private IEnumerator DelayUntilRalseiTalk()
	{
		yield return (object)new WaitForSeconds(1.5f);
		CutsceneIndex = 3;
		RunFreshChat(DoorCutscene_RalseiBegin, 0, ForcePosition: false, OnBottom: false);
	}

	private IEnumerator RalseiDoorOpen()
	{
		yield return (object)new WaitForSeconds(0.5f);
		RalseiAnim_Idle_Left();
		yield return (object)new WaitForSeconds(0.5f);
		RalseiAnim_Idle_Up();
		yield return (object)new WaitForSeconds(2f);
		backgroundRenderer.sprite = backgroundDoorOpenSprite;
		backgroundDoorGlow.SetActive(false);
		CutsceneSource.PlayOneShot(DoorOpenSound);
		CutsceneUtils.ShakeTransform(((Component)Camera).transform);
		yield return (object)new WaitForSeconds(1.5f);
		RalseiAnim_Idle_Down();
		RunFreshChat(DoorCutscene_RalseiFinale, 0, ForcePosition: false, OnBottom: false);
	}

	private void RunFreshChat(CHATBOXTEXT text, int index, bool ForcePosition, bool OnBottom)
	{
		DoorChat.FirstTextPlayed = false;
		DoorChat.CurrentIndex = index;
		DoorChat.FinishedText = false;
		DoorChat.Text = text;
		if (ForcePosition)
		{
			DoorChat.ManualTextboxPosition = true;
			DoorChat.OnBottom = OnBottom;
		}
		DoorChat.RUN();
	}

	private void CutsceneUpdate()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_037b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_041e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0423: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03db: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0492: Unknown result type (might be due to invalid IL or missing references)
		//IL_0497: Unknown result type (might be due to invalid IL or missing references)
		//IL_049d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		switch (CutsceneIndex)
		{
		case 1:
			if (((Component)PlayerManager.Instance).transform.position != KrisTargetPos)
			{
				((Component)PlayerManager.Instance).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)PlayerManager.Instance).transform.position), Vector2.op_Implicit(KrisTargetPos), 3f * Time.deltaTime));
			}
			if (((Component)Susie).transform.position != SusieTargetPos)
			{
				((Component)Susie).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)Susie).transform.position), Vector2.op_Implicit(SusieTargetPos), 3f * Time.deltaTime));
			}
			if (((Component)Ralsei).transform.position != RalseiTargetPos)
			{
				((Component)Ralsei).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)Ralsei).transform.position), Vector2.op_Implicit(RalseiTargetPos), 6f * Time.deltaTime));
			}
			if (((Component)Camera).transform.position.x != RalseiTargetPos.x)
			{
				((Component)Camera).transform.position = Vector3.MoveTowards(((Component)Camera).transform.position, new Vector3(RalseiTargetPos.x, ((Component)Camera).transform.position.y, ((Component)Camera).transform.position.z), 1.5f * Time.deltaTime);
			}
			if (((Component)Camera).transform.position.x == RalseiTargetPos.x && ((Component)PlayerManager.Instance).transform.position == KrisTargetPos && ((Component)Susie).transform.position == SusieTargetPos && ((Component)Ralsei).transform.position == RalseiTargetPos)
			{
				CutsceneIndex = 2;
				((MonoBehaviour)this).StartCoroutine(DelayUntilRalseiTalk());
			}
			break;
		case 4:
			((MonoBehaviour)this).StartCoroutine(RalseiDoorOpen());
			IncrementCutsceneIndex();
			break;
		case 6:
			LevelTransition.BeginTransition(0.25f);
			RalseiAnim_Idle_Left();
			IncrementCutsceneIndex();
			break;
		case 7:
			if (Vector2.op_Implicit(((Component)PlayerManager.Instance).transform.position) != Vector2.op_Implicit(KrisTargetPos) + Vector2.up * 3f)
			{
				PlayerManager.Instance._PMove._anim.SetBool("MOVING", true);
				((Component)PlayerManager.Instance).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)PlayerManager.Instance).transform.position), Vector2.op_Implicit(KrisTargetPos) + Vector2.up * 3f, 0.75f * Time.deltaTime));
			}
			if (Vector2.op_Implicit(((Component)Susie).transform.position) != Vector2.op_Implicit(SusieTargetPos) + Vector2.up * 3f)
			{
				Susie.SusieAnimator.SetBool("InCutscene", true);
				Susie.SusieAnimator.Play("Walk");
				((Component)Susie).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)Susie).transform.position), Vector2.op_Implicit(SusieTargetPos) + Vector2.up * 3f, 0.75f * Time.deltaTime));
			}
			if (Vector2.op_Implicit(((Component)Ralsei).transform.position) != Vector2.op_Implicit(RalseiTargetPos) + Vector2.right * 3f)
			{
				Ralsei.SusieAnimator.SetBool("InCutscene", true);
				Ralsei.SusieAnimator.Play("Walk");
				((Component)Ralsei).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)Ralsei).transform.position), Vector2.op_Implicit(RalseiTargetPos) + Vector2.right * 3f, 1f * Time.deltaTime));
			}
			break;
		case 2:
		case 3:
		case 5:
			break;
		}
	}

	public void IncrementCutsceneIndex()
	{
		CutsceneIndex++;
	}

	public void RalseiAnim_Idle_Down()
	{
		Ralsei.SusieAnimator.Play("Idle");
		Ralsei.SusieAnimator.SetFloat("VelocityX", 0f);
		Ralsei.SusieAnimator.SetFloat("VelocityY", -1f);
		Ralsei.SusieAnimator.SetFloat("VelocityMagnitude", 0f);
	}

	public void RalseiAnim_Idle_Left()
	{
		Ralsei.SusieAnimator.Play("Idle");
		Ralsei.SusieAnimator.SetFloat("VelocityX", -1f);
		Ralsei.SusieAnimator.SetFloat("VelocityY", 0f);
		Ralsei.SusieAnimator.SetFloat("VelocityMagnitude", 0f);
	}

	public void RalseiAnim_Idle_Up()
	{
		Ralsei.SusieAnimator.Play("Idle");
		Ralsei.SusieAnimator.SetFloat("VelocityX", 0f);
		Ralsei.SusieAnimator.SetFloat("VelocityY", 1f);
		Ralsei.SusieAnimator.SetFloat("VelocityMagnitude", 0f);
	}

	public void RalseiAnim_Blush_Down()
	{
		Ralsei.SusieAnimator.Play("Ralsei_Blush_Down");
	}

	public void RalseiAnim_Laugh()
	{
		Ralsei.SusieAnimator.Play("Ralsei_Laugh");
	}

	public void SusieAnim_Scratch()
	{
		Susie.SusieAnimator.Play("SusieDarkworld_Scratch");
	}

	public void SusieAnim_Idle_Up()
	{
		Susie.SusieAnimator.Play("Idle");
		Susie.SusieAnimator.SetFloat("VelocityX", 0f);
		Susie.SusieAnimator.SetFloat("VelocityY", 1f);
		Susie.SusieAnimator.SetFloat("VelocityMagnitude", 0f);
	}
}
